package com.itheima.controller;

import com.itheima.pojo.Clazz;
import com.itheima.pojo.ClazzQueryParam;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.service.ClassService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/clazzs")
public class ClassController {
    @Autowired
    private ClassService classService;
    @GetMapping
    public Result page(ClazzQueryParam  param){
        log.info("分页查询班级数据");
        PageResult<Clazz> clazzList = classService.findAll(param);
        return Result.success(clazzList);
    }
    @PostMapping
    public Result add(@RequestBody Clazz clazz){
        log.info("添加班级数据:{}",clazz);
        classService.add(clazz);
        return Result.success();
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("删除班级数据:{}",id);
        classService.delete(id);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
        log.info("查询班级数据:{}",id);
        Clazz clazz = classService.findById(id);
        return Result.success(clazz);
    }
    @GetMapping("/list")
    public Result list(){
        log.info("查询全部的班级数据");
        List<Clazz> clazzList = classService.list();
        return Result.success(clazzList);
    }
    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        log.info("修改班级数据:{}",clazz);
        classService.update(clazz);
        return Result.success();
    }
}
